/*
 * This file is part of JaTeCS.
 *
 * JaTeCS is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * JaTeCS is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with JaTeCS.  If not, see <http://www.gnu.org/licenses/>.
 *
 * The software has been mainly developed by (in alphabetical order):
 * - Andrea Esuli (andrea.esuli@isti.cnr.it)
 * - Tiziano Fagni (tiziano.fagni@isti.cnr.it)
 * - Alejandro Moreo Fernández (alejandro.moreo@isti.cnr.it)
 * Other past contributors were:
 * - Giacomo Berardi (giacomo.berardi@isti.cnr.it)
 */

package it.cnr.jatecs.clustering.kmeans;

import it.cnr.jatecs.clustering.interfaces.IClusterizerRuntimeCustomizer;
import it.cnr.jatecs.clustering.similarity.ISimilarityFunction;
import it.cnr.jatecs.clustering.similarity.KLSimilarity;
import it.cnr.jatecs.weighting.interfaces.IWeighting3D;


public class KMeansCustomizer implements IClusterizerRuntimeCustomizer {

    /**
     * The number of clusters to divide the entire domain space.
     */
    protected int _k;


    /**
     * The similarity function used.
     */
    protected ISimilarityFunction _similarity;


    /**
     * The algorithm convergence criterium to use.
     */
    protected IDocumentConvergeCriterion _convCriteria;


    /**
     * The precomputed probability distributions for the categories.
     */
    protected IWeighting3D _dists;


    /**
     * Minimum number of documents reassigned in an iteration to decrete that
     * the algorithm has converged.
     */
    private int _stopCriterion;

    /**
     * The set of intinial centroids.
     */
    private double[][] _centroids;


    private IClusterizerInitializer _initializer;


    public KMeansCustomizer() {
        _k = 10;
        _similarity = new KLSimilarity();
        _convCriteria = new NoReassignmentDocumentConvergeCriterion();
        _stopCriterion = 3;
        _centroids = null;
        _initializer = new RandomClusterizerInitalizer();
    }

    /**
     * Get the number of clusters that must be generated by algorithm.
     *
     * @return The number of clusters.
     */
    public int getNumberOfClusters() {
        return _k;
    }

    /**
     * Set the number of clusters to be generated by algorithm.
     *
     * @param k The number of clusters to generate.
     */
    public void setNumberOfClusters(int k) {
        if (k <= 0)
            k = 90;

        _k = k;
    }

    public ISimilarityFunction getSimilarityFunction() {
        return _similarity;
    }

    public void setSimilarityFunction(ISimilarityFunction func) {
        _similarity = func;
    }

    public IDocumentConvergeCriterion getConvergenceCriterion() {
        return _convCriteria;
    }

    public void setConvergenceCriterion(IDocumentConvergeCriterion criterion) {
        _convCriteria = criterion;
    }

    public IWeighting3D getDists() {
        return _dists;
    }


    public void setDists(IWeighting3D dists) {
        _dists = dists;
    }


    public int getStopCriterion() {
        return _stopCriterion;
    }


    public void setStopCriterion(int stopCriterion) {
        _stopCriterion = stopCriterion;
    }

    public double[][] getCentroids() {
        return _centroids;
    }

    public void setCentroids(double[][] centroids) {
        _centroids = centroids;
    }

    public IClusterizerInitializer getClusterizerInitializer() {
        return _initializer;
    }

    public void setClusterizerInitializer(IClusterizerInitializer initializer) {
        _initializer = initializer;
    }
}
